//
//  AVFootView.m
//  NewMusic
//
//  Created by dllo on 15/11/19.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "AVFootView.h"

@implementation AVFootView
- (void)dealloc
{
    [_startButton release];
    [_leftLabel release];
    [_rightLabel release];
    [_slider release];
    [_progress release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatSubView];
    }
    return self;
}
- (void)creatSubView
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 30)];
    view.backgroundColor = [UIColor blackColor];
    view.alpha = 0.2;
    [self addSubview:view];
    [view release];
    self.startButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.startButton.frame = CGRectMake(10, 5, 20, 20);
    [self.startButton setImage:[UIImage imageNamed:@"AV-stop"] forState:UIControlStateNormal];
    [self.startButton setImage:[UIImage imageNamed:@"AV-bofang"] forState:UIControlStateSelected];
    [self.startButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.startButton];
    
    self.leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 40, 30)];
    self.leftLabel.text = @"00:00";
    self.leftLabel.textAlignment = NSTextAlignmentCenter;
    self.leftLabel.textColor = [UIColor colorWithRed:200 / 255.0 green:200 / 255.0 blue:200 / 255.0 alpha:1.0];
    self.leftLabel.font = [UIFont fontWithName:@"ArialMT" size:13];
    [self addSubview:self.leftLabel];
    [_leftLabel release];
    
    self.progress = [[UIProgressView alloc] initWithFrame:CGRectMake(88, 13, 200, 10)];
    [self addSubview:self.progress];
    self.progress.progressTintColor = [UIColor grayColor];
    [_progress release];
    
    self.slider = [[UISlider alloc] initWithFrame:CGRectMake(86, 9, 203, 10)];
    [self.slider setThumbImage:[UIImage imageNamed:@"BF-dian"] forState:UIControlStateNormal];
    [self.slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    self.slider.minimumValue = 0;
    [self.slider setMinimumTrackTintColor:[UIColor colorWithRed:200 / 255.0 green:200 / 255.0 blue:200 / 255.0 alpha:1.0]];
    [self.slider setMaximumTrackTintColor:[UIColor clearColor]];
    [self addSubview:self.slider];
    [_slider release];
    
    self.rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(295, 0, 40, 30)];
    self.rightLabel.text = @"00:00";
    self.rightLabel.textAlignment = NSTextAlignmentCenter;
    self.rightLabel.textColor = [UIColor colorWithRed:200 / 255.0 green:200 / 255.0 blue:200 / 255.0 alpha:1.0];
    self.rightLabel.font = [UIFont fontWithName:@"ArialMT" size:13];
    [self addSubview:self.rightLabel];
    [_rightLabel release];
    
    self.fullButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.fullButton.frame = CGRectMake(345, 5, 20, 20);
    [self.fullButton setImage:[UIImage imageNamed:@"AV-quanping"] forState:UIControlStateNormal];
    [self.fullButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.fullButton];
}
- (void)buttonAction:(UIButton *)sender
{
    if (sender == self.startButton)
    {
        if (sender.selected)
        {
            [self.delegate changeAVStatusWith:0];
        } else {
            [self.delegate changeAVStatusWith:1];
        }
        sender.selected = !sender.selected;
    } else {
        [self.delegate setFullScreen];
    }
}
- (void)sliderAction:(UISlider *)sender
{
    [self.delegate changeAvSlider:sender.value];
}

@end
